{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "..downloading:\n",
      " https://raw.githubusercontent.com/mikedh/trimesh/master/models/machinist.XAML \n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "trimesh and vtkplotter interoperability\n",
    "\"\"\"\n",
    "\n",
    "# Install trimesh with:\n",
    "# sudo apt install python3-rtree\n",
    "# pip install rtree shapely\n",
    "# conda install trimesh\n",
    "\n",
    "import trimesh\n",
    "from vtkplotter import download, trimesh2vtk, show, embedWindow, closePlotter\n",
    "\n",
    "# uncomment this to pop a vtk rendering window instead of the K3D notebook backend\n",
    "embedWindow(False)\n",
    "\n",
    "url = 'https://raw.githubusercontent.com/mikedh/trimesh/master/models/'\n",
    "filename = download(url + 'machinist.XAML')\n",
    "mesh = trimesh.load(filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " vtkplotter 2019.3.5  | vtk 8.1.2 | python 3.6 | press h for help. \n"
     ]
    }
   ],
   "source": [
    "actor = trimesh2vtk(mesh) # returns a Actor(vtkActor) object from Trimesh\n",
    "\n",
    "# Any of these will work:\n",
    "show(mesh) # conversion is on the fly (don't need 'actor')\n",
    "\n",
    "# or\n",
    "#actor.show()\n",
    "\n",
    "# or\n",
    "#show(actor)\n",
    "\n",
    "# or\n",
    "#mesh.show() # this is the trimesh built-in visualizer\n",
    "\n",
    "# This closes the vtk rendering window. Use only if embedWindow(False)\n",
    "closePlotter()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
